USE Lib
GO

---------------------------------------------------------------------------
-- BEGIN MAINTENANCE WRAPPER
----------------------------
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'fn_nth_root') BEGIN
	DROP FUNCTION tsql.fn_nth_root
	PRINT '<<< DROP FUNCTION tsql.fn_nth_root - Completed with SUCCESS >>>'
END

GO
----------------------------
-- END MAINTENANCE WRAPPER
---------------------------------------------------------------------------

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


/*================================================================================================
Name:			tsql.fn_nth_root
Type:			User defined function 
Owner:			
Description:	extract the nth root of a real positive number
Parameters:		@number = number to extract root from
				@root = nth root 
Dependens on:  	none
Usage:			SELECT Lib.tsql.fn_nth_root(1234,12)
--------------------------------------------------------------------------------------------------
Project:		http://sqllib.codeplex.com/
Help:			http://sqllib.codeplex.com/wikipage?title=fn_nth_root&referringTitle=Documentation		
Version:		20120822
SrcCtrlApp:		SVN
SrcCtrlPath:	http://sqllib.codeplex.com/SourceControl/list/changesets
--------------------------------------------------------------------------------------------------
History:		09/11/2012 - Adrian E Dudau - Function created
================================================================================================*/
CREATE FUNCTION tsql.fn_nth_root(@number FLOAT, @root FLOAT) 
RETURNS FLOAT
AS 
BEGIN 
	RETURN POWER(@number ,1/@root)  
END
GO
---------------------------------------------------------------------------
-- BEGIN MAINTENANCE WRAPPER
-- Verify completion
----------------------------
IF EXISTS(SELECT * FROM sysobjects WHERE type = 'P' AND name = 'fn_nth_root') BEGIN 
	PRINT '<<< CREATE FUNCTION tsql.fn_nth_root - Completed with SUCCESS >>>'
END

ELSE BEGIN 
	PRINT '<<< CREATE FUNCTION tsql.fn_nth_root - Completed with ERROR >>>'
END


GO
----------------------------
-- END MAINTENANCE WRAPPER
---------------------------------------------------------------------------

--  GRANT SELECT TO PUBLIC will be used at Db level